<?php require_once('../../Connections/agriculture.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_bbsadminRecordset1 = 10;
$pageNum_bbsadminRecordset1 = 0;
if (isset($_GET['pageNum_bbsadminRecordset1'])) {
  $pageNum_bbsadminRecordset1 = $_GET['pageNum_bbsadminRecordset1'];
}
$startRow_bbsadminRecordset1 = $pageNum_bbsadminRecordset1 * $maxRows_bbsadminRecordset1;

if(isset($_GET['type'])){
$messageType=$_GET['type'];
}else{
$messageType=1;
}

mysql_select_db($database_agriculture, $agriculture);
$query_bbsadminRecordset1 = "SELECT * FROM message where message_classid=".$messageType;
$query_limit_bbsadminRecordset1 = sprintf("%s LIMIT %d, %d", $query_bbsadminRecordset1, $startRow_bbsadminRecordset1, $maxRows_bbsadminRecordset1);
$bbsadminRecordset1 = mysql_query($query_limit_bbsadminRecordset1, $agriculture) or die(mysql_error());
$row_bbsadminRecordset1 = mysql_fetch_assoc($bbsadminRecordset1);

if (isset($_GET['totalRows_bbsadminRecordset1'])) {
  $totalRows_bbsadminRecordset1 = $_GET['totalRows_bbsadminRecordset1'];
} else {
  $all_bbsadminRecordset1 = mysql_query($query_bbsadminRecordset1);
  $totalRows_bbsadminRecordset1 = mysql_num_rows($all_bbsadminRecordset1);
}
$totalPages_bbsadminRecordset1 = ceil($totalRows_bbsadminRecordset1/$maxRows_bbsadminRecordset1)-1;

$queryString_bbsadminRecordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_bbsadminRecordset1") == false && 
        stristr($param, "totalRows_bbsadminRecordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_bbsadminRecordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_bbsadminRecordset1 = sprintf("&totalRows_bbsadminRecordset1=%d%s", $totalRows_bbsadminRecordset1, $queryString_bbsadminRecordset1);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言管理</title>
</head>

<body>
<p><a href="bbsadmin.php?type=1">供应信息</a> <a href="bbsadmin.php?type=2">需求信息</a> <a href="bbsadmin.php?type=0">咨询信息</a> <a href="bbsposter.php">用户管理</a></p>
<table border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td>ID</td>
    <td>时间</td>
    <td> 发布者 </td>
    <td>标题</td>
    <td>内容</td>
    <td>状态</td>
    <td>可见性</td>
    <td>回复</td>
    <td>留言操作</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_bbsadminRecordset1['message_id']; ?></td>
      <td><?php echo $row_bbsadminRecordset1['message_time']; ?></td>
      <td><?php echo $row_bbsadminRecordset1['message_poster']; ?></td>
      <td><?php echo $row_bbsadminRecordset1['message_title']; ?></td>
      <td><?php echo $row_bbsadminRecordset1['message_content']; ?></td>
      <td><?php echo $row_bbsadminRecordset1['message_status']; ?></td>
      <td><?php echo $row_bbsadminRecordset1['message_visible']; ?></td>
      <td><?php echo $row_bbsadminRecordset1['message_reply']; ?></td>
      <td><a href="bbsadmin.php?action=<?php if($row_bbsadminRecordset1['message_visible']=='显示')echo 'hide';else echo 'show';?>&type=<?php echo $messageType;?>&id=<?php echo $row_bbsadminRecordset1['message_id'];?>"><?php if($row_bbsadminRecordset1['message_visible']=='显示')echo '不显示';else echo '显示'; ?></a>&nbsp;<a href="reply.php?id=<?php echo $row_bbsadminRecordset1['message_id'];?>">回复</a>&nbsp;<a href="bbsadmin.php?action=delete&type=<?php echo $messageType;?>&id=<?php echo $row_bbsadminRecordset1['message_id'];?>" onclick="return okToDelete()">删除</a></td>
    </tr>
    <?php } while ($row_bbsadminRecordset1 = mysql_fetch_assoc($bbsadminRecordset1)); ?>
</table>
<a href="<?php printf("%s?pageNum_bbsadminRecordset1=%d%s", $currentPage, max(0, $pageNum_bbsadminRecordset1 - 1), $queryString_bbsadminRecordset1); ?>">第一页</a> <a href="<?php printf("%s?pageNum_bbsadminRecordset1=%d%s", $currentPage, max(0, $pageNum_bbsadminRecordset1 - 1), $queryString_bbsadminRecordset1); ?>">上一页</a> <a href="<?php printf("%s?pageNum_bbsadminRecordset1=%d%s", $currentPage, min($totalPages_bbsadminRecordset1, $pageNum_bbsadminRecordset1 + 1), $queryString_bbsadminRecordset1); ?>">下一页</a> <a href="<?php printf("%s?pageNum_bbsadminRecordset1=%d%s", $currentPage, $totalPages_bbsadminRecordset1, $queryString_bbsadminRecordset1); ?>">最后页</a>
</body>
</html>

<script language="javascript">
function okToDelete(){
if(!confirm("确定删除留言?")){
return false;
}
return true;
}
</script>

<?php 
//如果不缺少参数,则进行相关操作
if(isset($_GET['action'])&&isset($_GET['id'])&&isset($_GET['type'])){

$action=$_GET['action'];
$id=$_GET['id'];
$type=$_GET['type'];

if($action=='show'){
$handleSql="update message set message_visible='显示' where message_id=".$id;
}

if($action=='hide'){
$handleSql="update message set message_visible='不显示' where message_id=".$id;
}

if($action=='delete'){
$handleSql="delete from message where message_id=".$id;
}

mysql_query($handleSql,$agriculture);

?>
<meta http-equiv=refresh content='0;url=<?php echo 'bbsadmin.php?type='.$type;?>'>


<?php
}

?>

<?php
mysql_free_result($bbsadminRecordset1);
?>
